package com.by.controller;

import com.by.bean.Customer;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;

/**
 * @author wang
 * @version 版本号 ${}
 * @className CustomerController
 * @日期 2024/9/13 15:54
 * @since jdk1.8
 */

@RequestMapping("v1")
@Api(tags = "客户管理")
@RestController
public class CustomerController extends BaseController {
    
    @Autowired
    CustomerService customerService;
    
    @ApiOperation("修改客户")
    @PutMapping("customer")
    public ResultBean update(@Validated @RequestBody Customer customer, BindingResult result){
        validate(result);
        
        int rs=customerService.update(customer);
        return updateResult(rs);
    }
    
    @ApiOperation("新增客户")
    @PostMapping("/customer/save")
    public ResultBean save(@Validated @RequestBody Customer customer,BindingResult Result){
        validate(Result);
        
        int rs=customerService.save(customer);
        return saveResult(rs);
    }
}
